package com.chenjim.architecture.screen.shimme

import android.os.SystemClock
import com.chenjim.architecture.base.BaseViewModel
import com.chenjim.architecture.base.IIntent
import com.chenjim.architecture.base.IState
import com.chenjim.architecture.screen.Order
import com.chenjim.architecture.screen.shimme.ShimmerScreenVM.UiIntent
import com.chenjim.architecture.screen.shimme.ShimmerScreenVM.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class ShimmerScreenVM @Inject constructor() : BaseViewModel<UiState, UiIntent>(UiState()) {

    override suspend fun handleIntent(intent: UiIntent) {
        when (intent) {
            UiIntent.InitIntent -> {
                SystemClock.sleep(2000)
                val list = listOf(
                    Order(
                        "酒后代驾",
                        "已完成",
                        "2024-01-01 22:56:12",
                        "浦东新区碧云路301弄-9号-101-b",
                        "浦东新区碧云路333弄-1号-101-b"
                    ),
                    Order(
                        "酒后代驾",
                        "已完成",
                        "2024-01-02 22:56:12",
                        "浦东新区碧云路302弄-9号-101-b",
                        "浦东新区碧云路333弄-1号-101-b"
                    ),
                    Order(
                        "酒后代驾",
                        "已取消",
                        "2024-01-03 22:56:12",
                        "浦东新区碧云路303弄-9号-101-b",
                        "浦东新区碧云路333弄-1号-101-b"
                    ),
                    Order(
                        "酒后代驾",
                        "已完成",
                        "2024-01-04 22:56:12",
                        "浦东新区碧云路304弄-9号-101-b",
                        "浦东新区碧云路333弄-1号-101-b"
                    ),
                )
                updateUiState { it.copy(isLoading = false, data = list) }
            }
        }
    }

    data class UiState(
        val isLoading: Boolean = true, val data: List<Order> = emptyList()
    ) : IState

    sealed class UiIntent : IIntent {
        data object InitIntent : UiIntent()
    }

}



